{% extends "wiki/base.html" %}
{% from "wiki/includes/sidebar_modules.html" import document_tools with context %}
{% from "wiki/includes/document_macros.html" import show_for, revision_diff with context %}
{% set title = _('Review Translation {id} | {document}')|f(document=document.parent.title, id=revision.id) %}
{% set crumbs = [(document.get_absolute_url(), document.title), (None, _('Review Translation'))] %}
{% set classes = 'review' %}
{% set scripts = ('wiki', 'wiki.diff') %}

{% block content %}
  <div class="grid_9">
    <article id="review-revision">
      <h1>{{ _('Review Translation of {title}')|f(title=document.parent.title) }}</h1>
      <p>{{ _('Reviewing Translation {id} in {language} by {user}.')|f(id=revision.id, user=revision.creator, language=settings.LANGUAGES_DICT[document.locale.lower()]) }}
        <a href="{{ url('wiki.document_revisions', document.slug) }}">{{ _('Back to History') }}</a>
        <br>
        {{ _('Translation Comment: {comment}')|f(comment=revision.comment) }}
      </p>

      {% if unreviewed_revisions %}
        <p>
          <div class="unreviewed-revision"> {{ ngettext('Unreviewed Revision:', 'Unreviewed Revisions:', unreviewed_revisions|length) }} </div>
          <br>
          <ul class="revision-comment">
            {% for revision in unreviewed_revisions %}
              <li>
                {{ _('Revision {id} by {user}.')|f(id=revision.id, user=revision.creator) }}
                <br>
                {{ _('<label>Revision Comment:</label> {comment}')|fe(comment=revision.comment) }}
                <br>
                <a href="{{ url('wiki.review_revision', document.slug, revision.id) }}">{{ _('Review Revision {id}')|f(id=revision.id) }}</a>
              </li>
            {% endfor %}
          </ul>
        </p>
      {% endif %}

      {% if revision.reviewed %}
        <p>
          {{ _('This translation was already reviewed by {user} on {date}.')|fe(user=revision.reviewer, date=datetimeformat(revision.reviewed, format='longdatetime')) }}
        </p>
      {% elif current_revision_id > revision.id %}
        <p>
          {% if latest_unapproved_revision_id > current_revision_id %}
            {{ _('This version is outdated, but there is a new version available.') }}
            <a href="{{ url('wiki.review_revision', document.slug, latest_unapproved_revision_id) }}">{{ _('Please review the latest version.') }}</a>
          {% else %}
            {{ _('A newer version has already been reviewed.') }}
          {% endif %}
        </p>
      {% elif document.current_revision %}
        {# If there is a parent revision to diff, and this translation is not already based on it. #}
        {% if parent_revision and document.current_revision.based_on and
              document.current_revision.based_on != parent_revision %}
          <details class="h2" open="open">
            <summary>{{ _('Recent English Changes') }}</summary>
            {# Default locale diff #}
            {{ revision_diff(document.current_revision.based_on, parent_revision, show_picker=True) }}
          </details>
        {% endif %}
        <details class="h2" open="open">
          <summary>{{ _('Submitted Translation Changes') }}</summary>
          {# Current locale diff #}
          {{ revision_diff(document.current_revision, revision, _('Current public translation:'), _('Submitted translation:')) }}
        </details>
        <details class="h2"{% if not parent_revision %} open="open"{% endif %}>
          <summary>{{ _('Full Article Sources') }}</summary>
          {% if not parent_revision %}
            <div class="warning-box">
              {{ _('The {default_locale} version has no approved content to show.')|f(default_locale=settings.LANGUAGES_DICT[settings.WIKI_DEFAULT_LANGUAGE.lower()]) }}
            </div>
          {% else %}
            {# Default vs. current locale #}
            <div id="content-fields" class="revision-diff">
              <div class="approved">
                <h3>{{ _('Approved {default_locale} version:')|f(default_locale=settings.LANGUAGES_DICT[settings.WIKI_DEFAULT_LANGUAGE.lower()]) }}</h3>
                <p>{{ _('Revision {id} by {user} on {date}')|fe(id=parent_revision.id, user=parent_revision.creator, date=datetimeformat(parent_revision.created, format='longdatetime')) }}</p>
              </div>
              <div class="localized">
                <h3>{{ _('Submitted {locale} translation:')|f(locale=settings.LANGUAGES_DICT[document.locale.lower()]) }}</h3>
                <p>{{ _('Revision {id} by {user} on {date}')|fe(id=revision.id, user=revision.creator, date=datetimeformat(revision.created, format='longdatetime')) }}</p>
              </div>
              <h4>{{ _('Keywords:') }}</h4>
              <div class="approved">
                <p>{{ parent_revision.keywords }}</p>
              </div>
              <div class="localized">
                <p>{{ revision.keywords }}</p>
              </div>
              <h4>{{ _('Search results summary:') }}</h4>
              <div class="approved">
                <p>{{ parent_revision.summary }}</p>
              </div>
              <div class="localized">
                <p>{{ revision.summary }}</p>
              </div>
              <h4>{{ _('Content:') }}</h4>
              <div class="approved">
                <textarea readonly="readonly">{{ parent_revision.content }}</textarea>
              </div>
              <div class="localized">
                <textarea readonly="readonly">{{ revision.content }}</textarea>
              </div>
            </div>
          {% endif %}
        </details>
        <details class="h2">
          <summary>{{ _('Revision Content') }}</summary>
          <div id="doc-content">
            {{ revision.content_parsed|safe }}
          </div>
          {{ show_for(document.get_products(), _('Article is for:')) }}
        </details>
      {% else %}
        <p>{{ _('This document does not have a current translation.') }}</p>
        <h3>{{ _('Translation keywords:') }}</h3>
        <div id="revision-keywords">
          {{ revision.keywords }}
        </div>
        <h3>{{ _('Translation search results summary:') }}</h3>
        <div id="revision-summary">
          {{ revision.summary }}
        </div>
        <h3>{{ _('Translation source:') }}</h3>
        <div id="revision-content">
          <pre>{{ revision.content }}</pre>
        </div>
        <h3>{{ _('Translation rendered html:') }}</h3>
        <div id="revision-html">
          <div id="doc-content">
            {{ revision.content_parsed|safe }}
          </div>
        </div>
      {% endif %}

      {% include 'wiki/includes/review_form.html' %}
    </article>
  </div>
{% endblock %}

{% block side_top %}
  {{ document_tools(document, document.parent, user, '', settings) }}
{% endblock %}

{% block side_bottom %}
  {% if not revision.reviewed and not document.current_revision %}
    {{ show_for(document.get_products(), _('Article is for:')) }}
  {% endif %}
{% endblock %}

{% block side %}
{% endblock %}
